import BaseMsg from "./BaseMsg";
import { uploadFile } from "@/api/im";

export default class VideoMsg extends BaseMsg {
    constructor() {
        super();
        this.setMsgType("file");
    }

    setFile(file) {
        // 上传文件
        return new Promise((resolve, reject) => {
            uploadFile(file)
                .then(res => {
                    if (res.code == 200) {
                        let msgData = {
                            fileUrl: res.data.fileUrl,
                            fileName: res.data.fileName,
                        };
                        this.setMsgData(JSON.stringify(msgData));
                        resolve(msgData);
                    } else {
                        reject(res.msg);
                    }
                })
                .catch(err => {
                    reject(err);
                });
        });
    }
}
